define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop.member/index' + location.search,
                    add_url: 'shop.member/add',
                    edit_url: 'shop.member/edit',
                    del_url: 'shop.member/del',
                    multi_url: 'shop.member/multi',
                    import_url: 'shop.member/import',
                    table: 'shop_member',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'shop_id', title: __('Shop_id')},
                        {field: 'member_id', title: __('Member_id')},
                        {field: 'is_admin', title: __('Is_admin')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'is_del', title: __('Is_del')},
                        {field: 'member.id', title: __('Member.id')},
                        {field: 'member.member_avatar', title: __('Member.member_avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'member.member_mobile', title: __('Member.member_mobile'), operate: 'LIKE'},
                        {field: 'member.member_name', title: __('Member.member_name'), operate: 'LIKE'},
                        {field: 'member.member_sex', title: __('Member.member_sex')},
                        {field: 'member.member_province', title: __('Member.member_province'), operate: 'LIKE'},
                        {field: 'member.member_city', title: __('Member.member_city'), operate: 'LIKE'},
                        {field: 'member.mini_openid', title: __('Member.mini_openid'), operate: 'LIKE'},
                        {field: 'member.balance', title: __('Member.balance'), operate:'BETWEEN'},
                        {field: 'member.default_shop_id', title: __('Member.default_shop_id')},
                        {field: 'member.source', title: __('Member.source')},
                        {field: 'member.createtime', title: __('Member.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'member.logintime', title: __('Member.logintime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'member.login_ip', title: __('Member.login_ip'), operate: 'LIKE'},
                        {field: 'member.birthday', title: __('Member.birthday')},
                        {field: 'member.integral', title: __('Member.integral')},
                        {field: 'member.total_integral', title: __('Member.total_integral')},
                        {field: 'member.update_time', title: __('Member.update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'member.status', title: __('Member.status')},
                        {field: 'member.is_vip', title: __('Member.is_vip')},
                        {field: 'member.member_nickname', title: __('Member.member_nickname'), operate: 'LIKE'},
                        {field: 'member.discount', title: __('Member.discount'), operate:'BETWEEN'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
